# Maintainer: m0rf30 <morf3089@gmail.com>
# Reference: <https://postmarketos.org/devicepkg>
pkgname=device-xiaomi-vince
pkgdesc="Xiaomi Redmi Note 5 Plus"
pkgver=1
pkgrel=0
url="https://postmarketos.org"
license="MIT"
arch="aarch64"
options="!check !archcheck"
depends="postmarketos-base linux-xiaomi-vince mkbootimg mesa-dri-swrast msm-fb-refresher"
makedepends="devicepkg-dev"
subpackages="$pkgname-nonfree-firmware:nonfree_firmware"

source="deviceinfo
	fb.modes
	pointercal
	misc/100-charging.rules
	misc/buttons.conf
	misc/charging.sh
	misc/discharging.sh
	misc/vince-audioctl.sh
	ucm/msm8953-snd-card-mtp/HiFi.conf
	ucm/msm8953-snd-card-mtp/msm8953-snd-card-mtp.conf
	"

build() {
	devicepkg_build $startdir $pkgname
}

package() {
	devicepkg_package $startdir $pkgname
	install -Dm644 "$srcdir"/fb.modes "$pkgdir"/etc/fb.modes
	install -Dm644 "$srcdir"/pointercal "$pkgdir"/etc/pointercal
	install -Dm644 "$srcdir"/100-charging.rules \
		"$pkgdir"/etc/udev/rules.d/100-charging.rules
	install -Dm755 "$srcdir"/charging.sh "$pkgdir"/usr/lib/device-xiaomi-vince/charging.sh
	install -Dm755 "$srcdir"/discharging.sh "$pkgdir"/usr/lib/device-xiaomi-vince/discharging.sh
	install -Dm755 "$srcdir"/vince-audioctl.sh "$pkgdir"/usr/lib/device-xiaomi-vince/vince-audioctl.sh

	# Disable v4l udev rules (video4linux), because without the camera
	#         firmware blobs this makes udev helper hang (#1033)
	mkdir -p "$pkgdir"/etc/udev/rules.d
	ln -s /dev/null "$pkgdir"/etc/udev/rules.d/60-persistent-v4l.rules
}

nonfree_firmware() {
	pkgdesc="Wi-Fi, ADSP Firmware"
	depends="firmware-xiaomi-vince wcnss-wlan adsp-audio pulseaudio pulseaudio-alsa alsa-plugins-pulse alsa-utils"
	install="$pkgname-nonfree-firmware.post-install"
	mkdir "$subpkgdir"

	# Install triggerhappy evdev rules for vince
	install -Dm755 "$srcdir"/buttons.conf "$pkgdir"/etc/triggerhappy/triggers.d/buttons.conf

	# Install UCM files for vince
	install -Dm644 "$srcdir"/HiFi.conf \
		"$subpkgdir"/usr/share/alsa/ucm2/msm8953-snd-card-mtp/HiFi.conf
	install -Dm644 "$srcdir"/msm8953-snd-card-mtp.conf \
		"$subpkgdir"/usr/share/alsa/ucm2/msm8953-snd-card-mtp/msm8953-snd-card-mtp.conf
}

sha512sums="2e31117082ced7b1cd20c5a3b253d934795bb6b65fea316e7e67efd36ce98b546d828077daa5781b9a90101b540b687b5c27e87b812b4e42fec0ba77c9cb61d4  deviceinfo
9b888f3a4ef3ed3c0b2e9c6a6e8a6c686909c530c3d95be797b47b4eb9deb55d64190b7a3736e44139630bfff5e295625a855052923369fdd37889060a3220ca  fb.modes
4fa63c184f00033fbae2e4b140c9655061b3b662e337f7bdf5f8e26f7b57d6c66ad01fc93da05ce7d330f0f05bb0d36cc9b356ebfc7eb4200be4d4cc03afc975  pointercal
b6951e2f8d2e21aa58f15b600a67289900d645b9dcff9992d0864dea383528539fc8b0140bff6af4eba4bb729db79a3d5d88ba248fcf2b579dd8c3cd0e20ae4e  100-charging.rules
922519b787ab8d6886f3b2e0ace84de69d0e185208776aedd471828132d13bc6364393cd5c7f97634de014aaf3fb100c9fa4724c97d6d1220320d2e73e0f1947  buttons.conf
89195cfaa131eef1a34c882685ed53eb0e80d1520cf9924e775875bde1de883448f3d182775f8323b261afaf0f6a5e73aa31142f2e72acc3ac584a64de6e72a3  charging.sh
947fb09b7dce638d28afb367ce193437092bca956647486d67438a3fbb695c9354bc1174a68a5993644c3c619f9826cb8a84b8b9f49b513a484089a965b665c5  discharging.sh
24762c3f4b0d1e9a035495c05e53852a68d46699e1f41915bd6d68af3d2a22dad075c77209533d92a81693aa45c86018ce825a8b7e7a8c163b59d826d9e204d1  vince-audioctl.sh
8b0ec10746d98d905041ec18bcc0bfae1961bed574a280ca903a5a5ec71de14df0429c5b49ce25835555c076565d8c35285d7a3b7152e21aa4d1b97659e012eb  HiFi.conf
f7dfd0c863f4c0d3746533bd3d0885b88ac73fb3b158522da5b57b636a4048d0c68a143f76e6750bb1404893c4803a86928671d4b60e93d253fe4b62d7a2f5f6  msm8953-snd-card-mtp.conf"
